package ynu.edu.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import ynu.edu.dao.IUserDao;
import ynu.edu.po.User;

@RestController
@RequestMapping(value = "/stu")
public class StudentController {

    @Resource
    private IUserDao sDao;

    // Hello API
    @GetMapping(value = "/hello")
    public String hello() {
        return "Student Controller";
    }

    // Login API
    @PostMapping(value = "/login")
    public User login(@RequestParam(value = "id") String stuId, @RequestParam(value = "pwd") String password) {
        // 查询数据库，查找学生信息并返回
        return sDao.findStudentByStuIdAndPassword(Long.valueOf(stuId), password);
    }

    // Create Student API
    @PostMapping(value = "/createStu")
    public User insert(@RequestBody User stu) {
        // 保存新的学生信息到数据库
        return sDao.save(stu);
    }
}
